package cn.edu.suda.catalina.dataupdate.util;

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import java.io.File;

/**
 * Created by admin on 2017/5/18.
 */
public class JavaCompilerUtil {

    /**
     * 动态编译java类
     * @param filePath java类
     * @return
     */
    public static int compile(String filePath, String className) {
        String file = filePath + File.separator + ClassNameUtil.getSimpleName(className);
        JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler(); //jdk提供的编译类
        return javaCompiler.run(null, null, null, file);   //interface Tool方法
    }
}
